package cn.stylefeng.guns.modular.demo.controller;

import cn.stylefeng.guns.modular.demo.controller.domain.ReportQueryRequest;
import cn.stylefeng.guns.modular.demo.controller.domain.ReportVO;
import cn.stylefeng.guns.modular.demo.controller.domain.YearReportVO;
import cn.stylefeng.guns.modular.demo.service.ReportService;
import cn.stylefeng.roses.kernel.rule.enums.ResBizTypeEnum;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@ApiResource(name = "报表", resBizType = ResBizTypeEnum.BUSINESS, path = "/report")
public class ReportController {
    @Resource
    private ReportService reportService;

    /**
     * @author fengshuonan
     * @since 2021/1/24 10:59
     */
    @PostResource(name = "返利报表", path = "/rebate/list", requiredLogin = true, requiredPermission = true)
    @ApiOperation("查询规则列表")
    @ResponseBody
    public ResponseData<List<ReportVO>> list(@RequestBody ReportQueryRequest request) {
        List<ReportVO> reportVOS = reportService.generateReport(request.getStartTime(), request.getEndTime(), request.getSupplierIdList(), request.getGoodsIdList(), request.getSaleStockIdList());
        return new SuccessResponseData<>(reportVOS);
    }

    /**
     * @author fengshuonan
     * @since 2021/1/24 10:59
     */
    @PostResource(name = "销售额报表", path = "/year/list", requiredLogin = true, requiredPermission = true)
    @ApiOperation("销售额报表")
    @ResponseBody
    public ResponseData<List<YearReportVO>> listYearReport(@RequestBody ReportQueryRequest request) {
        List<YearReportVO> yearReportVOS = reportService.generateYear(request.getStartTime(), request.getEndTime(), request.getSupplierIdList());
        return new SuccessResponseData<>(yearReportVOS);
    }


}
